package cn.csg.iotplatform.module.system.dal.mysql.projectcopy;

import cn.csg.iotplatform.framework.common.pojo.PageResult;
import cn.csg.iotplatform.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.csg.iotplatform.framework.mybatis.core.mapper.BaseMapperX;
import cn.csg.iotplatform.module.system.dal.dataobject.projectcopy.ProjectDO;
import org.apache.ibatis.annotations.Mapper;
import cn.csg.iotplatform.module.system.controller.admin.project.vo.*;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

/**
 * 项目信息 Mapper
 *
 * @author 系统管理员
 */
@Mapper
public interface ProjectMapper extends BaseMapperX<ProjectDO> {

    default PageResult<ProjectDO> selectPage(ProjectPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<ProjectDO>()
                .likeIfPresent(ProjectDO::getProjectNo, reqVO.getProjectNo())
                .likeIfPresent(ProjectDO::getProjectName, reqVO.getProjectName())
                .eqIfPresent(ProjectDO::getUnitCode, reqVO.getUnitCode())
                .likeIfPresent(ProjectDO::getUnitName, reqVO.getUnitName())
                .eqIfPresent(ProjectDO::getUnitUser, reqVO.getUnitUser())
                .eqIfPresent(ProjectDO::getUnitTel, reqVO.getUnitTel())
                .eqIfPresent(ProjectDO::getConstructionCode, reqVO.getConstructionCode())
                .likeIfPresent(ProjectDO::getConstructionName, reqVO.getConstructionName())
                .eqIfPresent(ProjectDO::getConstructionUser, reqVO.getConstructionUser())
                .eqIfPresent(ProjectDO::getConstructionTel, reqVO.getConstructionTel())
                .eqIfPresent(ProjectDO::getDataSource, reqVO.getDataSource())
                .eqIfPresent(ProjectDO::getEnablingStatus, reqVO.getEnablingStatus())
                .betweenIfPresent(ProjectDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(ProjectDO::getGatewayDeviceNum, reqVO.getGatewayDeviceNum())
                .eqIfPresent(ProjectDO::getSubDeviceNum, reqVO.getSubDeviceNum())
                .eqIfPresent(ProjectDO::getCommonDeviceNum, reqVO.getCommonDeviceNum())
                .eqIfPresent(ProjectDO::getDescription, reqVO.getDescription())
                .inIfPresent(ProjectDO::getId,reqVO.getIds())
                .orderByDesc(ProjectDO::getCreateTime));
    }


    @Update("UPDATE IM_DV_DEVICE_BASE SET project_name = #{projectName} WHERE project_id  = #{projectId}")
    void updateDeviceBase(@Param("projectId") String projectId, @Param("projectName") String projectName);
}